<?php
/**
 * Bread Crumb
 * 
 * @author Xavier VILAIN
 * @package \Nawa\MedicalStudy
 * @license
 */
use Nawa\MedicalStudy\MedicalCenter\Monitoring;
use Nawa\MedicalStudy\MedicalCenter\Patient;
use Fox\Generator;
use Nawa\Messages;
use Fox\Html\BreadCrumb\Crumb;

$customerid = isset($params['customerid']) ? $params['customerid'] : null;
$customer_name = isset($params['customer_name']) ? $params['customer_name'] : null;
$deepness = isset($params['deepness']) ? $params['deepness'] : 0;
$msCounter = isset($params['msCounter']) ? $params['msCounter'] : null;
$msLabel = isset($params['msReference']) ? $params['msReference'] : null;
$msCenterCount = isset($params['msCenterCount']) ? $params['msCenterCount'] : 0;
$msid = isset($params['msid']) ? $params['msid'] : 0;
$mcid = isset($params['mcid']) ? $params['mcid'] : null;
$mcLabel =  isset($params['mcLabel']) ? $params['mcLabel'] : null;
$mcPatientCount = isset($params['mcPatientCount']) ? $params['mcPatientCount'] : 0;
$patient =  isset($params['patient']) ? $params['patient'] : null;
$mcMonitoringCount = isset($params['mcMonitoringCount']) ? $params['mcMonitoringCount'] : 0;
$monitoring =  isset($params['monitoring']) ? $params['monitoring'] : null;
$type =  isset($params['type']) ? $params['type'] : null;

$crumbs[] = new Crumb('customer_search',
					Generator::url('customers','search',null,array('customerid' => $customerid)),
					Msg(Messages::BUNDLE,Messages::LABEL_CUSTOMER)
					);
if(!empty($customerid))
{

	$crumbs[] = new Crumb('customer',
	Generator::url('customers','update',null,array('customerid' => $customerid)),
	$customer_name,
	false);
	if($deepness == 0)
	{
		$crumbs[] = new Crumb('studies',
		Generator::url('customers','medicalstudies',null,array('customerid' => $customerid)),
		Msg(Messages::BUNDLE,Messages::LABEL_STUDIES)." (".$msCounter.")",
		true);
	}
	elseif($deepness > 0)
	{
		$crumbs[] = new Crumb('studies',
		Generator::url('customers','medicalstudies',null,array('customerid' => $customerid)),
		Msg(Messages::BUNDLE,Messages::LABEL_STUDIES),
		true);
		if($deepness == 1)
		{
			$crumbs[] = new Crumb('new_study',null,Msg(Messages::BUNDLE,Messages::LABEL_NEW_STUDY));
		}
		else
		{

			$crumbs[] = new Crumb('study',Generator::url('medicalstudies','update',null,array('msid' => $msid)),$msLabel);
			$crumbs[] = new Crumb('centers',
			Generator::url('medicalstudies','centers',null,array('msid' => $msid)),
			Msg(Messages::BUNDLE,Messages::LABEL_MEDICAL_CENTERS)." (".$msCenterCount.")",true);
			if($deepness >= 3)
			{
				if($deepness == 3) {
					$crumbs[] = new Crumb('center',null,$mcLabel);
				} else {
					$crumbs[] = new Crumb('center',Generator::url('medicalstudies','medicalcenter',null,array('msid' => $msid,'mcid' => $mcid)),$mcLabel);
				}
				
			}
		}
		if($deepness >= 3 && $type == Patient::BREADCRUMB_NODE) {
			$generator = null;
			if($deepness != 4) {
				$generator = Generator::url('medicalstudies',
								'patients',
								null,
								array('msid' => $msid,'mcid' => $mcid));
			}
			// Patient Sub Screen
			$crumbs[] = new Crumb('patients',$generator,
				Msg(Messages::BUNDLE,Messages::LABEL_PATIENTS)." (".$mcPatientCount.")",true);
			if($deepness == 5 && !empty($patient)) {
				$crumbs[] = new Crumb('patient',null,$patient->label(),false);
			}
		} 
		if($deepness >= 3 && $type == Monitoring::BREADCRUMB_NODE) {
			$generator = null;
			if($deepness != 4) {
				$generator = Generator::url('medicalstudies',
								'medicalcenters',
								'monitorings_summary',
								array('msid' => $msid,'mcid' => $mcid));
			}
			// Monitoring Sub Screen
			$crumbs[] = new Crumb('monitorings',$generator,
				Msg(Messages::BUNDLE,Messages::MONITORINGS)." (".$mcMonitoringCount.")",true);
			if($deepness == 5 ) {
				if(!empty($monitoring)) {
					$label = $monitoring->label();
				} else {
					$label = Msg(Messages::BUNDLE,Messages::MONITORING_ADD);
				}
				$crumbs[] = new Crumb('monitoring',null,$label,false);
			}
		}
	}
}
else
{
	$crumbs[] = new Crumb('studies',
	Generator::url('customers','medicalstudies',null,array('customerid' => $customerid)),
	Msg(Messages::BUNDLE,Messages::LABEL_STUDIES),
	true);
}
return $crumbs;